package com.sgb.goods.view.adapter.publish.pop;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgb.goods.R;
import com.sgb.goods.entity.AlbumEntity;
import com.sgb.goods.view.adapter.publish.SelectAlbumAdapter;
import com.sgb.goods.widget.pop.GoodsPopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.util.MToast;

import java.util.List;

public class SelectAlbumPopWindow extends GoodsPopWindow<String> {

    private RecyclerView netAlbumRecycler;
    private SelectAlbumAdapter selectAlbumAdapter;
    private List<AlbumEntity> datas;
    private TextView tvCancel;
    private TextView tvPhoneAlbum;

    public SelectAlbumPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
    }

    @Override
    protected int popLayout() {
        return R.layout.goods_pop_select_album;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        netAlbumRecycler = holder.getPop().findViewById(R.id.net_album_recycler);
        tvCancel = holder.getPop().findViewById(R.id.tv_cancel);
        tvPhoneAlbum = holder.getPop().findViewById(R.id.tv_phone_album);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        selectAlbumAdapter = new SelectAlbumAdapter();
        netAlbumRecycler.setLayoutManager(linearLayoutManager);
        netAlbumRecycler.setAdapter(selectAlbumAdapter);
        selectAlbumAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                MToast.showToast(mContext, "暂未实现商砼的网络相册选择,需要先实现商砼类别选择");
//                onResultClick.result(1, null, null);
//                ARouter.getInstance().build(Constants.ARouter.AR_GOODS_ALBUM)
//                        .withSerializable("albumEntity", selectAlbumAdapter.getData().get(position))
//                        .navigation();
            }
        });

        tvPhoneAlbum.setOnClickListener(v -> {
            onResultClick.result(0, null, null);
            dismiss();
        });
        tvCancel.setOnClickListener(v -> {
            dismiss();
        });
    }

    public void setData(List<AlbumEntity> datas) {
        this.datas = datas;
        if (datas.size() < 0) {
            return;
        }
        selectAlbumAdapter.setNewData(datas);
    }
}
